package test

import (
	"github.com/golang/mock/gomock"
	"gorm.io/gorm"
	feedv1 "jk-time/webook/api/proto/gen/feed/v1"
	mocksFollow "jk-time/webook/api/proto/gen/follow/v1/mocks"
	"jk-time/webook/feed/dao"
	"jk-time/webook/feed/grpc"
	"jk-time/webook/feed/ioc"
	"jk-time/webook/feed/repository"
	"jk-time/webook/feed/service"
	"testing"
)

func InitGrpcServer(t *testing.T) (feedv1.FeedSerivceServer, *mocksFollow.MockFollowServiceClient, *gorm.DB) {
	db := ioc.InitDB()
	feedPullEventDAO := dao.NewFeedPullEventDAO(db)
	feedPushEventDAO := dao.NewFeedPushEventDAO(db)
	feedEventRepo := repository.NewFeedRepository(feedPullEventDAO, feedPushEventDAO)
	mockCtrl := gomock.NewController(t)
	followClient := mocksFollow.NewMockFollowServiceClient(mockCtrl)
	v := ioc.RegisterHandler(feedEventRepo, followClient)
	feedService := service.NewFeedService(feedEventRepo, followClient, v)
	feedEventGrpcSvc := grpc.NewFeedEventGrpcSvc(feedService)
	return feedEventGrpcSvc, followClient, db
}
